package netTracker;

/**
 * Contains utility methods for NetTracker.
 * @author David Cummings
 */
public class Util {

	private boolean debug;
	private Object obj;
	
	/**
	 * Creates a Utility class.
	 * @param debug sets debug flag
	 */
	public Util (Object obj, boolean debug){
		this.obj = obj;
		this.debug = debug;
	}
	
	/**
	 * Prints debugging information if the debug flag is true.
	 * @param msg an error message to print
	 */
	public void debug(String msg){
		if(debug){
			System.err.println(obj.getClass().getName()+":"+msg); /* TODO figure out how to include getClass().getName() + ": "+*/
		}
	}
	
	/**
	 * Prints debugging information if the debug flag is true.
	 * @param msg an error message to print
	 */
	public void debug(Exception e){
		if(debug){
			System.err.println(obj.getClass().getName()+":"+e); /* TODO figure out how to include getClass().getName() + ": "+*/
		}
	}

	/**
	 * A utility method that maps tempos in BPM to a delay in milliseconds required to achieve the tempo.
	 * @param tempo the tempo to map
	 * @return the delay in ms required to match the tempo
	 */
	public static long mapTempoToDelay(double tempo) {
		return (long)(15000.0 / tempo);
	}
}
